package com.topView2;

/**
 * 编写一个函数来查找字符串数组中的最长公共前缀
 *
 * @Author: huangzhigao
 * @Date: 2023/2/11 17:20
 */
public class leecode14 {
    public String longestCommonPrefix(String[] strs) {
        int index = 0;
        boolean flag = false;
        while (index < strs[0].length()) {
            char c = strs[0].charAt(index);
            for (int i = 1; i < strs.length; i++) {
                if (index == strs[i].length() || strs[i].charAt(index) != c) {
                    flag = true;
                    break;
                }
            }

            if (flag) {
                break;
            }
            index++;
        }
        return strs[0].substring(0, index);

    }
}
